import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import Home2 from './views/Home2.vue'

Vue.use(Router)
const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      meta: {
        title: '首页入口'
      }

    },
    {
      path: '/h2',
      name: 'home2',
      component: Home2,
      meta: {
        title: '首页入口2'
      }

    },
    {
      path: '/about',
      name: 'about',
      meta: {
        title: '首页入口3'
      }
      ,
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    }
  ]
})

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router